import axios from 'axios'
import { useUserStore } from '../store/user'

const api = axios.create({
  baseURL: 'http://localhost:8080/api', // 后端服务地址
  timeout: 10000
})

// 请求拦截器：自动携带token
api.interceptors.request.use(config => {
  const store = useUserStore()
  if (store.token) {
    config.headers.Authorization = `Bearer ${store.token}`
  }
  return config
})

// 可按需添加请求/响应拦截器

export default api 